 // src/utils/socket.ts
import { io } from 'socket.io-client';

const socket = io("http://localhost:3001/",{
    path: "/socket.io/", // 替换为后端地址
}); // 替换为后端地址

export const useSocket = () => {
  const sendMessage = (data) => {
    socket.emit('message', data); // 发送消息到后端
  };

  const onMessage = (callback) => {
    socket.on('response', callback); // 监听后端响应
  };

  return { sendMessage, onMessage };
};